package cn.liyao.web.repository;

import cn.liyao.web.model.Conversation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ConversationRepository extends JpaRepository<Conversation, String> {


    Conversation findOneByUserIdAndTargetId(String userId,String targetId);

    List<Conversation> findAllByUserIdOrderByTimestampAsc(String userId);


    void deleteByTargetIdAndUserId(String targetId, String userId);


    @Modifying
    @Query("update UserMessage m set m.deletedStatus = 1   where  m.targetId = :targetId and m.userId = :userId ")
    void updateDeletedStatusByTargetId(@Param("targetId") String targetId,@Param("userId") String userId);



}